package com.example.evensystem.model.entity

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import java.sql.Date
import java.sql.Time
import java.time.LocalDate


@Entity(
    tableName = "dailywork", primaryKeys = arrayOf("id", "date"),
    foreignKeys = arrayOf(
        ForeignKey(
            entity = Worker::class,
            parentColumns = ["id"],
            childColumns = ["id"],
            onDelete = ForeignKey.CASCADE,
            onUpdate = ForeignKey.CASCADE
        )
    )
)
data class DailyWork(
    //日期
    val date: String,//YYYY-MM-dd
    //工号
    val id: String,
    //上班时间
    val arriveTime: String,//HH:mm:ss
    //下班时间
    val leaveTime: String,
    //是否迟到
    val isLate: Boolean,
    //是否早退
    val isLeftEarly: Boolean

)

@Dao
interface DailyWorkDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(dailyWork: DailyWork)

    @Delete
    fun delete(dailyWork: DailyWork)

    @Query("select * from dailywork where id=:id and date=:date")
    fun find(id: String, date: String): List<DailyWork>

    @Update
    fun update(dailyWork: DailyWork)
}

